package com.movitech.mobile.cz.base.modules.activiti.service;

import java.util.Map;

import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ActivitiRuntimeService {
	protected Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	private RuntimeService runtimeService;

	public ProcessInstance startProcessInstanceById(String processDefinitionId) {
		return runtimeService.startProcessInstanceById(processDefinitionId);
	}

	public ProcessInstance startProcessInstanceById(String processDefinitionId, String businessKey) {
		return runtimeService.startProcessInstanceById(processDefinitionId, businessKey);
	}

	public ProcessInstance startProcessInstanceById(String processDefinitionId, String businessKey, Map<String, Object> variables) {
		return runtimeService.startProcessInstanceById(processDefinitionId, businessKey, variables);
	}

	public ProcessInstance startProcessInstanceById(String processDefinitionId, Map<String, Object> variables) {
		return runtimeService.startProcessInstanceById(processDefinitionId, variables);
	}

	public ProcessInstance startProcessInstanceByKey(String processDefinitionKey) {
		return runtimeService.startProcessInstanceByKey(processDefinitionKey);
	}

	public ProcessInstance startProcessInstanceByKey(String processDefinitionKey, String businessKey) {
		return runtimeService.startProcessInstanceByKey(processDefinitionKey, businessKey);
	}

	public ProcessInstance startProcessInstanceByKey(String processDefinitionKey, String businessKey, Map<String, Object> variables) {
		return runtimeService.startProcessInstanceByKey(processDefinitionKey, businessKey, variables);
	}

	public ProcessInstance startProcessInstanceByKey(String processDefinitionKey, Map<String, Object> variables) {
		return runtimeService.startProcessInstanceByKey(processDefinitionKey, variables);
	}

	/***
	 * 查询流程是否结束
	 * @param processInstanceId
	 * @return
	 */
	public boolean isProcessEnd(String processInstanceId) {
		boolean isEnd = false;
		ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
		if (processInstance == null) {
			isEnd = true;
		}
		return isEnd;
	}
}
